package com.augurit.gzcgwsp.ywcmn.service.impl;

import java.util.List;
import java.util.Map;

import com.augurit.gzcgwsp.exchangeOtherData.dao.ExChangeDataDao;
import com.augurit.gzcgwsp.ywcmn.entity.YwDzgzList;


/**
 * 保存盖章附件
 * @author Administrator
 *
 */
public class YwDzgzService {

	/**
	 * 保存盖章的信息
	 * @return
	 */
	public String save(YwDzgzList entity){
		ExChangeDataDao dao=new ExChangeDataDao();
		Long ajid=entity.getAjid();
		String templateCode=entity.getTemplateCode();
		String findsql=" select * from YW_DZGZ_LIST where ajid="+entity.getAjid()
					+" and template_code='"+entity.getTemplateCode()+"' and filename='"+entity.getFilename()+"'";
		String idsql=" select SEQ_YW_DZGZ_LIST.nextval as val from dual ";
		List list=dao.queryForList(findsql);
	
		if(list!=null && list.size()>0){
			Map map=(Map) list.get(0);
			String id=(String) map.get("id");
			entity.setId(Long.valueOf(id));
		}
		Long id=entity.getId();
		String sql="";
		if(id!=null){
			sql=" update YW_DZGZ_LIST set filepath='"+entity.getFilepath()+"',username='"+
					entity.getUsername()+"',uploaddate=sysdate where id="+entity.getId();
		}else{
			List listId=dao.queryForList(idsql);
			Map idMap=(Map) listId.get(0);
			String idval=(String) idMap.get("val");
			entity.setId(Long.valueOf(idval));
			sql=" insert into YW_DZGZ_LIST (id,ajid,filename,template_code,";
			sql+=" filepath,username,uploaddate) values ("+entity.getId()+",";
			sql+=entity.getAjid()+",'"+entity.getFilename()+"','"+entity.getTemplateCode()+"','";
			sql+=entity.getFilepath()+"','"+entity.getUsername()+"',sysdate)";
		}
		int num=dao.updateDateBase(sql);
		if(num>0){
			return "success";
		}
		return null;
	}
	
}
